var e = require;
var t = module;
var n = exports;
var o =
        (this && this.__assign) ||
        function () {
            return (o =
                Object.assign ||
                function (e) {
                    for (var t, n = 1, o = arguments.length; n < o; n++)
                        for (var i in (t = arguments[n])) Object.prototype.hasOwnProperty.call(t, i) && (e[i] = t[i]);
                    return e;
                }).apply(this, arguments);
        },
    s =
        (this && this.__spreadArrays) ||
        function () {
            for (var e = 0, t = 0, n = arguments.length; t < n; t++) e += arguments[t].length;
            for (var o = Array(e), i = 0, t = 0; t < n; t++)
                for (var r = arguments[t], a = 0, s = r.length; a < s; a++, i++) o[i] = r[a];
            return o;
        };
Object.defineProperty(n, "__esModule", {value: !0}),
    (n.delayCallFunc =
        n.copy =
        n.flatDeep =
        n.uniqueArray =
        n.getInArrayIndex =
        n.includeInArray =
        n.mergeDeep =
        n.isObject =
        n.clampStr =
        n.filterNullValues =
        n.filterOneRightTwoWarnOpt =
        n.removeTwoWarnOptions =
        n.questionThunk =
        n.randomChoice =
        n.shuffleArr =
        n.sleep =
        n.compareVersion =
        n.random =
        n.randomInt =
        n.isTouchInNode =
        n.disableTouch =
        n.tempDisableButton =
        n.disableBtn =
        n.disableAllTouch =
        n.showNode =
        n.curCanvas =
        n.getScreenHeight =
        n.getScreenWidth =
            void 0),
    (n.getScreenWidth = function () {
        return cc.view.getCanvasSize().width;
    }),
    (n.getScreenHeight = function () {
        return cc.view.getCanvasSize().height;
    }),
    (n.curCanvas = function () {
        var e = cc.director.getScene();
        return cc.find("Canvas", e);
    }),
    (n.showNode = function (e, t, n, o) {
        void 0 === o && (o = 0),
            null != e &&
                (n && ((e.scale = 0), cc.tween(e).delay(o).to(n, {scale: 1}).start()), null != e && (e.active = t));
    });
var i = null;
function r(e, t) {
    e.interactable = !t;
}
function a(e) {
    for (var t = e.length - 1; 0 <= t; t--) {
        var n = Math.floor(Math.random() * (t + 1)),
            o = e[n];
        (e[n] = e[t]), (e[t] = o);
    }
    return e;
}
function c(e, t) {
    return a(Object.assign([], e)).slice(0, t);
}
function l(e) {
    return e && "object" == typeof e && !Array.isArray(e);
}
function u(e, t) {
    if (null == e || null == t) return -1;
    for (var n = e.length, o = 0; o < n; ++o) if (t === e[o]) return o;
    return -1;
}
(n.disableAllTouch = function (e) {
    var t;
    null == i &&
        ((t = (t = cc.director.getScene().getComponentInChildren(cc.Canvas).node.children)[t.length - 1]),
        (i = t.getComponent(cc.BlockInputEvents))),
        (i.enabled = e);
}),
    (n.disableBtn = r),
    (n.tempDisableButton = function (e, t) {
        if ((void 0 === t && (t = 0), null != e)) {
            e instanceof cc.Event.EventTouch && (e = e.target);
            var n = null;
            if (
                (e instanceof cc.Button ? (n = e) : e instanceof cc.Node && (n = e.getComponent(cc.Button)), null != n)
            ) {
                var o = function () {
                    r(n, !1);
                };
                return (
                    r(n, !0),
                    n.scheduleOnce(o, t),
                    function () {
                        o(), n.unschedule(o);
                    }
                );
            }
        }
    }),
    (n.disableTouch = function (e, t) {
        t ? e.pauseSystemEvents(!0) : e.resumeSystemEvents(!0);
    }),
    (n.isTouchInNode = function (e, t) {
        if ((1, null == e || null == t)) return !1;
        t = e.convertToNodeSpaceAR(t.getLocation());
        return t.x >= -e.width / 2 && t.x <= e.width / 2 && t.y >= -e.height / 2 && t.y <= e.height / 2;
    }),
    (n.randomInt = function (e, t) {
        return Math.round(Math.random() * (t - e)) + e;
    }),
    (n.random = function (e, t) {
        return Math.random() * (t - e) + e;
    }),
    (n.compareVersion = function (e, t) {
        for (var n = e.split("."), o = t.split("."), i = Math.max(n.length, o.length); n.length < i; ) n.push("0");
        for (; o.length < i; ) o.push("0");
        for (var r = 0; r < i; r++) {
            var a = parseInt(n[r]),
                s = parseInt(o[r]);
            if (s < a) return 1;
            if (a < s) return -1;
        }
        return 0;
    }),
    (n.sleep = function (t, n) {
        return new Promise(function (e) {
            n
                ? n.scheduleOnce(function () {
                      e();
                  }, t)
                : setTimeout(function () {
                      e();
                  }, 1e3 * t);
        });
    }),
    (n.shuffleArr = a),
    (n.randomChoice = c),
    (n.questionThunk = function (e, t) {
        var n = e.question.answer,
            o = [];
        if (
            (n.map(function (e, t) {
                o.push({answer: 0 === t, desc: e, select: t});
            }),
            t)
        ) {
            t = o[2];
            return (o[2] = o[0]), (o[0] = t), (e.question.qlist = o), e;
        }
        return (o = a(o)), (e.question.qlist = o), e;
    }),
    (n.removeTwoWarnOptions = function (e, t) {
        void 0 === t && (t = !1);
        var n = [],
            o = [],
            i = a(e);
        if (t)
            return (
                e.map(function (e) {
                    e.isTrue || n.push(e);
                }),
                n
            );
        for (var r = 0; r < i.length && 2 != n.length; r++)
            i[r].isTrue ? ((i[r].tipOrHelp = !0), o.push(i[r])) : ((i[r].tipOrHelp = !1), n.push(i[r]));
        return n;
    }),
    (n.filterOneRightTwoWarnOpt = function (e, t, n) {
        var o = [],
            i = [];
        if ((n = void 0 === n ? !1 : n))
            return (
                e.map(function (e) {
                    e.isTrue && (o.push(e.desc), i.push(e));
                }),
                {helps: o, cells: i}
            );
        for (var r = 0; r < e.length; r++)
            e[r].isTrue && (o.push(e[r].desc), i.push(e[r]), (e.tipOrHelp = !1), e.splice(r, 1));
        for (var a = c(e, t), r = 0; r < a.length; r++) (a[r].tipOrHelp = !1), o.push(a[r].desc), i.push(a[r]);
        return {helps: o, cells: i};
    }),
    (n.filterNullValues = function (e, t) {
        var n = e;
        (t = void 0 === t ? !1 : t) || (n = Object.assign({}, e));
        for (var o = Object.keys(n), i = 0; i < o.length; i++) {
            var r = o[i],
                a = n[r];
            (null != a && void 0 !== a) || delete n[r];
        }
        return n;
    }),
    (n.clampStr = function (e, t, n) {
        (n = null == (n = void 0 === n ? null : n) ? "..." : n), (t *= 2);
        for (
            var o = (function (e) {
                    for (var t, n = [], o = 0, i = 0; i < e.length; ) {
                        var r = i;
                        65039 != (t = e.charCodeAt(i++)) &&
                            (o
                                ? (n.push({v: 65536 + ((o - 55296) << 10) + (t - 56320), pos: r}), (o = 0))
                                : 55296 <= t && t <= 56319
                                ? (o = t)
                                : n.push({v: t, pos: r}));
                    }
                    return n;
                })(e),
                i = 0,
                r = 0,
                a = 0;
            a < o.length;
            ++a
        ) {
            var s = 1.5;
            if (t < i + (s = 128 <= o[a].v ? 2 : s)) break;
            (r = a), (i += s);
        }
        return o.length - 1 == r ? e : e.substring(0, o[r - (n ? 1 : 0)].pos + 1) + n;
    }),
    (n.isObject = l),
    (n.mergeDeep = function e(t) {
        for (var n, o = [], i = 1; i < arguments.length; i++) o[i - 1] = arguments[i];
        if (!o.length) return t;
        var r = o.shift();
        if (l(t) && l(r))
            for (var a in r)
                l(r[a])
                    ? (t[a] || Object.assign(t, (((n = {})[a] = {}), n)), e(t[a], r[a]))
                    : Object.assign(t, (((n = {})[a] = r[a]), n));
        return e.apply(void 0, s([t], o));
    }),
    (n.includeInArray = function (e, t) {
        return -1 !== u(e, t);
    }),
    (n.getInArrayIndex = u),
    (n.uniqueArray = function (e) {
        return Array.from(new Set(e));
    }),
    (n.flatDeep = function n(e, o) {
        return 0 < (o = void 0 === o ? 1 : o)
            ? e.reduce(function (e, t) {
                  return e.concat(Array.isArray(t) ? n(t, o - 1) : t);
              }, [])
            : e.slice();
    }),
    (n.copy = function (e) {
        return o({}, e);
    }),
    (n.delayCallFunc = function (e, t) {
        t <= 0
            ? e()
            : setTimeout(function () {
                  e();
              }, t);
    });
